package psn.kiko.mapper.ddl.table;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 查看某个数据库(tableSchema)有哪些表及其详细信息
 */
@Mapper
public interface TableListMapper {
	/**
	 * 查询指定数据库的表的详细信息列表
	 * @param tableSchema 库名
	 * @return 表信息集合
	 */
	@Select("SELECT\n" +
			"t.TABLE_NAME,\n" +
			"t.TABLE_COMMENT,\n" +
			"t.TABLE_ROWS,\n" +
			"t.AUTO_INCREMENT,\n" +
			"t.TABLE_SCHEMA,\n" +
			"t.TABLE_TYPE,\n" +
			"t.`ENGINE`,\n" +
			"t.DATA_LENGTH,\n" +
			"t.MAX_DATA_LENGTH,\n" +
			"t.AVG_ROW_LENGTH,\n" +
			"t.INDEX_LENGTH,\n" +
			"t.DATA_FREE,\n" +
			"t.TABLE_COLLATION,\n" +
			"t.VERSION,\n" +
			"t.ROW_FORMAT,\n" +
			"t.CREATE_TIME,\n" +
			"t.UPDATE_TIME,\n" +
			"t.CHECK_TIME\n" +
			"FROM\n" +
			"information_schema.`TABLES` AS t\n" +
			"WHERE t.TABLE_SCHEMA='${tableSchema}';")
	List<Map<String,String>> tablesOfSchema(@Param("tableSchema") String tableSchema);
}
